const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => document.querySelectorAll(selector);

const doms = $$(".item");
const h = window.innerHeight;

window.addEventListener("scroll", () => {
  doms.forEach((dom) => {
    const rect = dom.getBoundingClientRect();
    if (rect.top < -h || rect.top > h) {
      return;
    }
    dom.style.backgroundPositionY = -(rect.top / 2) + "px";
  });
});
